# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
"""
"""
from .. import formlib as layout

LEFT, RIGHT = layout.LEFT, layout.RIGHT


class AcesUpLayout(layout.Layout):
    """
    static block:
      - rows [N] `_offset` if `playcards`. `ncols` wide.

    dynamic block: align [LEFT | RIGHT].
      - talon [NW | NE].
      - waste [E talon | W talon]. `wastecards` ignored.
      - reserves [S] talon. (vert) `_offset` if `holdcards`. `ncards` if
        `reserve_texts`.
      - foundations [NE | NW]. (vert SUITS. max 5 rows.) `ncards` if len is
        `1`.

    :CVariables:
        _offset: func
          .. dict('ycards': [play|hold]cards)
          Margin and offset is below piles.
    """
    _offset = lambda self, cards: {'ycards': cards}

    def create(self, rows, ncols=None, playcards=12, bases=None,
               reserves=0, holdcards=0, reserve_texts=False,
               texts=True, align=LEFT, **kw):
        """
        create(rows[, ncols=rows, playcards=12, bases=suits * decks,
               reserves=0, holdcards=0, reserve_texts=False,
               texts=True, align=LEFT]) -> None

        :Parameters:
          rows : int
            Num of `s.rows` to include.

          ncols : int
            Num of horz piles before starting new row. Default `ROWS`.

          playcards : int
            Num of possible cards as margin on each pile on `s.rows`. A value
            of 0 sets no offset and a value greater sets an offset. Default
            `12`.

          bases : tuple | list
            Value of each `suit` capabilty on `s.foundations`. Len is num of
            piles to include. Default `SUITS * DECKS`.

          reserves : int
            Num of `s.reserves` piles to include. Default `0`.

          holdcards : int
            Num of possible cards as margin on each pile on `s.reserves`. A
            value of 0 sets no offset and a value greater sets an offset.
            Default `0`.

          reserve_texts : bool
            Whether to include num cards text label for `s.reserves`. Default
            `False`.

          texts : bool
            Whether to include num cards text label for `s.talon` and possible
            `s.waste`. Default `True`.

          align : LEFT | RIGHT
            Dynamic placement of `s.talon`, possible `s.waste`, and possible
            `s.reserves`. `s.foundations` placement is opposite side. Default
            `LEFT`
        """
        l, s = self, self.s
        ncols = ncols or rows
        # Set foundation
        bases = bases if type(bases) in (list, tuple) else l.SUITS
        f_rows = min(5, l.NSUIT if bases is l.SUITS else len(bases))
        # Allow sub class
        ix = max(l.size.width, l.XM)
        # Static align row N
        sx = (ix + l.XS if align == RIGHT
                        else ix + (1 + int(l._has_waste)) * l.XS)
        l._set_rows(x=sx, y=l.size.height, rows=rows, ncols=ncols,
                    **l._offset(playcards))
        # Dynamic align to opposite edge vert foundation
        dx = (ix if align == RIGHT else l.size.width + l.XM)
        l._set_vert_foundations(x=dx, y=l.YM, nrows=f_rows, bases=bases)
        # Dynamic align to `align` edge talon, waste
        dx = ix if align == LEFT else l.size.width + l.XM
        l._set_horz_talon(x=dx, y=l.YM, texts=texts, align=align,
                          anchor='s', wastecards=0)
        anchor = 'e' if align == LEFT else 'w'
        s['talon'].set_rounds(anchor='sss' if l._has_waste else anchor)
        # Dynamic align to `align` edge vert reserve S talon
        dy = l.TEXT_HEIGHT * 2 if texts else 0
        l._set_vert_reserves(x=dx, y=dy, reserves=reserves,
                             reserve_texts=reserve_texts, anchor='w',
                             **l._offset(holdcards))